<template>
  <div>
    <!-- 潜在客户详情 -->
    <el-card class="card">
      <!-- 老人信息 -->
      <div class="header">
        <div class="header_left">
          <span class="line" />
          <span>老人信息</span>
        </div>
        <h2>未签约</h2>
      </div>
      <div class="content">
        <div class="txt">老人姓名：{{ ruleForm.name }}</div>
        <div class="txt">老人性别：{{ ruleForm.gender == 1 ? "男" : "女" }}</div>
        <div class="txt">身份证号：{{ ruleForm.idCard }}</div>
        <div class="txt">老人状况：{{ ruleForm.source }}</div>
      </div>
      <!-- 家属信息 -->
      <div class="header">
        <div class="header_left">
          <span class="line" />
          <span>家属信息</span>
        </div>
      </div>
      <!-- 家属信息表格 -->
      <el-table :data="ruleForm.family" style="width: 100%">
        <el-table-column prop="id" label="序号" width="180" />
        <el-table-column prop="name" label="姓名" width="180" />
        <el-table-column prop="gender" label="性别">
          <template #default="scope">{{ scope.row.gender == 1 ? "男" : "女" }}</template>
        </el-table-column>
        <el-table-column prop="idCard" label="身份证号" />
        <el-table-column prop="mobile" label="联系电话" />
        <el-table-column prop="address" label="联系地址" />
        <el-table-column prop="relation" label="与老人关系" />
      </el-table>
      <!-- 需求信息 -->
      <div class="header">
        <div class="header_left">
          <span class="line" />
          <span>需求信息</span>
        </div>
      </div>
      <div class="need">
        <div class="txt">房间需求：{{ ruleForm.roomRequire }}</div>
        <div class="txt">意向需求：{{ ruleForm.content }}</div>
      </div>
      <div class="backBtn">
        <el-button @click="back">返回</el-button>
      </div>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { reactive, onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { AddParams } from "../../api/market/customer/type";
import { getCustomerModel } from "../../api/market/customer/customer";

const route = useRoute();
const router = useRouter();
const currentId = ref(0);

onMounted(() => {
  // console.log("routeid", route.params.id);
  if (route.params.id) {
    currentId.value = Number(route.params.id);
    getDetailById();
  }
});

const getDetailById = async () => {
  let res = await getCustomerModel(currentId.value);
  // console.log("1111", res);
  if (res) {
    console.log(2277);

    Object.assign(ruleForm, res);
  }
};

//添加老人信息
const ruleForm = reactive<AddParams>({
  name: "",
  mobile: "",
  gender: null,
  birthday: null,
  status: "",
  idCard: "",
  roomRequire: "",
  content: "",
  state: 1,
  source: "在线咨询",
  family: [],
});

//返回
const back = () => {
  router.push("/market/customer");
};
</script>

<style scoped>
.card {
  width: 98%;
  margin: 0 auto;
  margin-top: 10px;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 50px;

    .header_left {
      display: flex;
      align-items: center;

      .line {
        display: block;
        width: 6px;
        height: 20px;
        margin-right: 8px;
        background-color: #529bfd;
      }
    }
  }

  .content {
    margin-top: 40px;

    .txt {
      height: 32px;
      margin-bottom: 18px;
      font-size: 14px;
      line-height: 32px;
    }
  }

  .need {
    .txt {
      height: 32px;
      margin-bottom: 18px;
      font-size: 14px;
      line-height: 32px;
    }
  }

  .backBtn {
    text-align: center;
  }
}
</style>
